--select c.Mobile, Max(u.CreatedDate) from tblCXCRMCallStatus cs 
--INNER JOIN tblCEContact c ON cs.CustomerID = c.RefCEUserID
--INNER JOIN tblCEUser u ON cs.CustomerID = u.CEID
--Where u.UsrTypeID = 400 AND cs.MainCallStatusTypeID = 6
--Group By c.Mobile 
--Order By Max(u.CreatedDate) DESC
--select * from tblReportsUser

--select Convert(varchar(12), l.CreatedDate, 113), 
--CASE l.IsFromService WHEN 0 THEN 'OLD' ELSE 'NEW' END LeadType,
--Count(l.AgentLeadID) 
--FROM tblCXCRMAgentLeads l
--Where Convert(varchar(8), l.CreatedDate, 112) Between '20130531' And '20130607'
--And l.IsFromService IS NOT NULL
--Group By Convert(varchar(12), l.CreatedDate, 113), l.IsFromService
--Order By Convert(varchar(12), l.CreatedDate, 113) DESC

--select top 10 * from tblCXCRMAgentLeads Where IsFromService = 0 And [Status] = 1

--select top 10 * from tblCEUser Where CEID = 50785

select Max(c.CreatedDate), Min(c.CreatedDate), count(l.AgentLeadID), l.Status, l.IsFromService from tblCXCRMAgentLeads l
INNER JOIN tblCarDetailTH c ON l.CarID = c.CarID
Where Convert(varchar(8), l.CreatedDate, 112) = Convert(varchar(8), GetDate(), 112)
Group By l.Status, l.IsFromService

select Max(c.CreatedDate), Min(c.CreatedDate), count(l.AgentLeadID), l.AgentID, l.Status from tblCXCRMAgentLeads l
INNER JOIN tblCarDetailTH c ON l.CarID = c.CarID
Where Convert(varchar(8), l.CreatedDate, 112) = Convert(varchar(8), GetDate(), 112) And l.IsFromService = 2 And l.Status = 1
Group By l.Status, l.AgentID

select count(a.CECarID), l.IsFromService
from tblCXCRMAgentLeads l
INNER JOIN tblCarDetailTH c ON l.CarID = c.CarID
INNER JOIN tblNonGGCarMoreDetails a ON l.CarID = a.CeCarID
Where Convert(varchar(8), l.CreatedDate, 112) = Convert(varchar(8), GetDate(), 112)
Group By l.IsFromService


Select Convert(varchar(8), GetDate() - 10, 112)
--DELETE FROM l
--from tblCXCRMAgentLeads l 
--INNER JOIN tblCarDetailTH cd ON l.CustomerID = cd.RefCEUserID and l.CarID = cd.CarID
--INNER JOIN tblCarPolicy cp ON l.CustomerID = cp.RefCEUserID and l.CarID = cp.CECarID
--Where Convert(varchar(8), cd.CreatedDate, 112) < '20130410' And l.Status = 1
--And l.AgentID IN (547, 4425, 18818, 18808, 8543, 18813)

--select top 10 * from tblNonGGTransaction Where TransactionTypeID = 300 Order By ModifiedDate DESC

--select CEID from tblCEUser
--Where CEID in (Select CustomerID from tblCXCRMAgentLeads)
--And UsrTypeID = 1001

--**********DELETE EXPIRED LEAD***********
--select cp.SumInsured, cp.CoverageCommenceDate, cp.CreatedDate from tblCarPolicy cp
--Where Convert(varchar(8), cp.CreatedDate, 112) = Convert(varchar(8), GetDate()-2, 112)
--And Convert(varchar(8), cp.CoverageCommenceDate, 112) = Convert(varchar(8), GetDate(), 112)
--And cp.RefCEUserID NOT IN (select distinct CustomerID from tblCXCRMAgentLeads Where Convert(varchar(8), CreatedDate, 112) > '20130218')


--select c.CarID, c.RefCEUserID, cp.CoverageCommenceDate, l.AgentID, l.CallType, c.CreatedDate, l.Status, l.CreatedDate
--from tblCXCRMAgentLeads l 
--INNER JOIN tblCarDetailTH c ON l.CarID = c.CarID
--INNER JOIN tblCarPolicy cp ON l.CArID = cp.CECarID
--INNER JOIN tblCEUser u ON u.CEID = l.CustomerID
--Where u.UsrTypeID = 400 And l.Status = 1 And cp.CoverageCommenceDate+1 < GetDate()

--DELETE FROM tblCXCRMAgentLeads
--FROM         tblCXCRMAgentLeads INNER JOIN
--                      tblCarDetailTH AS c ON tblCXCRMAgentLeads.CarID = c.CarId INNER JOIN
--                      tblCarPolicy AS cp ON tblCXCRMAgentLeads.CarID = cp.CECarId INNER JOIN
--                      tblCEUser AS u ON u.CEID = tblCXCRMAgentLeads.CustomerID
--WHERE     (u.UsrTypeId = 400) AND (tblCXCRMAgentLeads.Status = 1) AND (cp.CoverageCommenceDate + 1 < GETDATE())
--*****END DELETE EXPIRED LEAD *********

--Check Leads Count
--select Count(l.AgentLeadID), Convert(varchar(8), u.CreatedDate, 112) from tblCXCRMAgentLeads l 
--INNER JOIN tblCEUser u ON l.CustomerID = u.CEID
--And U.usrTypeID = 400 And Convert(varchar(6), u.CreatedDate, 112) =  '201302'
--Group By Convert(varchar(8), u.CreatedDate, 112)

--547	broker1@gluaygluay.com 
--18808	broker3@gluaygluay.com
--8543	broker5@gluaygluay.com
--18813	broker6@gluaygluay.com
--31575	broker7@gluaygluay.com
--18818	broker8@comparexpress.co.th
select getdate()
--select s.CallBackDateTime, s.AgentID, Count(l.AgentLeadID) from tblCXCRMAgentLeads l INNER JOIN tblCXCRMCallStatus s
--ON l.AgentLeadID = s.AgentLeadID
--Where s.CallBackDateTime IS NOT NULL And Convert(varchar(8), s.CallBackDateTime,112) > '20130130' and l.[Status] = 2
--Group By s.CallBackDateTime, s.AgentID
--Having Count(l.AgentLeadID) > 1

Declare @OldStartDate varchar(8)
Declare @OldEndDate varchar(8)
Declare @LeadStartDate varchar(8)
Declare @LeadEndDate varchar(8)
Declare @strStartCommDate varchar(8)
Declare @strEndCommDate varchar(8)

SET @strEndCommDate = Convert(varchar(8), DateAdd(year, -1, GetDate()) + 90, 112)
SET @strStartCommDate = Convert(varchar(8), DateAdd(year, -1, GetDate()) + 0, 112)

SET  @LeadStartDate = Convert(varchar(8), DateAdd(day, -60, GetDate()), 112)
SET  @LeadEndDate = Convert(varchar(8), GetDate(), 112)

SET @OldStartDate = Convert(varchar(8), DateAdd(year, -1, GetDate()), 112)
SET @OldEndDate = Convert(varchar(8), DateAdd(year, -1, GetDate()) + 5, 112)

	SELECT 
	u.CEID, 
	--CASE WHEN up.NInfo7 IS NULL THEN 1 ELSE up.NInfo7 END AS IsENCustomer,
	up.NInfo7 AS IsENCustomer,
	Max(cd.CarID) CarID,
	MAX(cp.SumInsured),
	Max(cp.CoverageCommenceDate),
	Max(cd.CreatedDate),
	Min(cd.CreatedDate)
	FROM tblCEUser u 
	INNER JOIN tblCEUsrProfile up ON u.CEID = up.RefCEUserID
	INNER JOIN tblCarDetailTH cd ON u.CEID = cd.RefCEUserID
	INNER JOIN tblCarPolicy cp ON u.CEID = cp.RefCEUserID
	Where u.UsrTypeID = 400
	AND cd.CarID > 0 AND u.CEID > 0
	AND (Convert(varchar(8), cp.CoverageCommenceDate, 112) Between @strStartCommDate And @strEndCommDate)
	And (Convert(varchar(8), u.CreatedDate, 112) Between @OldStartDate And @OldEndDate)
	AND ((cd.Info8 NOT Like '%[A-Z,a-z]%' AND (LEN(cd.Info7) = 0 OR cd.Info7 NOT Like '%[A-Z,a-z]%')) OR (up.NInfo7 = 1 OR up.NInfo7 = 0))
	And u.CEID NOT IN (Select distinct CustomerID from tblCXCRMAgentLeads Where (Convert(varchar(8), CreatedDate, 112) Between @LeadStartDate And @LeadEndDate))
	And u.CEID NOT IN (select distinct RefCEUserID  from tblNonGGCarMoreDetails)
	AND u.CEID NOT IN (select distinct CustomerID from tblCXCRMCallStatus Where MainCallStatusTypeID = 6)
	Group By u.CEID, up.NInfo7
	ORDER BY Max(cp.CoverageCommenceDate) DESC, MAX(cp.SumInsured) DESC

select Convert(varchar(8), u.CreatedDate, 112), Count(u.CEID) AS 'CUSTOMER COUNT'  from tblCEUser u INNER JOIN 
tblCarDetailTH cd ON u.CEID = cd.RefCEUserID
Where Convert(varchar(8), u.CreatedDate, 112) 
Between Convert(varchar(8), DateAdd(day, -7, GETDATE()), 112)  And Convert(varchar(8), GETDATE(), 112) 
And UsrTypeID = 400
Group By Convert(varchar(8), u.CreatedDate, 112) 
ORDER BY Convert(varchar(8), u.CreatedDate, 112)

select Convert(varchar(8), u.CreatedDate, 112), Count(u.CEID) AS 'OLD CUSTOMER COUNT' from tblCEUser u INNER JOIN 
tblCarDetailTH cd ON u.CEID = cd.RefCEUserID
Where Convert(varchar(8), u.CreatedDate, 112) 
Between Convert(varchar(8), DateAdd(year, -1, GETDATE()), 112) And Convert(varchar(8), DateAdd(day, 7, DateAdd(year, -1, GETDATE())), 112) 
And UsrTypeID = 400
Group By Convert(varchar(8), u.CreatedDate, 112) 
ORDER BY Convert(varchar(8), u.CreatedDate, 112)

Select AVG(t.[OLD CUSTOMER COUNT]) FROM(
select Convert(varchar(8), u.CreatedDate, 112) CreatedDate, Count(u.CEID) AS 'OLD CUSTOMER COUNT' from tblCEUser u INNER JOIN 
tblCarDetailTH cd ON u.CEID = cd.RefCEUserID
Where Convert(varchar(8), u.CreatedDate, 112) 
Between Convert(varchar(8), DateAdd(year, -1, GETDATE()), 112) And Convert(varchar(8), DateAdd(day, 7, DateAdd(year, -1, GETDATE())), 112) 
And UsrTypeID = 400
Group By Convert(varchar(8), u.CreatedDate, 112)) AS t


Select '' AS [POLICY NOT SOON], l.AgentLeadID, c.CallBackAgentID, c.CallBackDateTime
from tblCXCRMAgentLeads l 
INNER JOIN tblCXCRMCallStatus c ON l.AgentLeadID = c.AgentLeadID AND c.CallTypeID = l.CallType
INNER JOIN tblCEUser u ON u.CEID = l.CustomerID		
Where u.UsrTypeId = 400 AND l.Status = 100 
And c.MainCallStatusTypeID = 7 And c.CallStatusTypeID = 10
AND c.CallBackDateTime IS NOT NULL And c.CallBackAgentID IS NOT NULL
--And c.CallBackAgentID = @AgentID 
And (DateDiff(Day, GETDATE(), c.CallBackDateTime) <= 45)
ORDER BY c.CallBackDateTime ASC
	

Declare @hourAdd smallint

SET @hourAdd = 2

Declare @QuoteDateStart smallint
Declare @QuoteDateEnd smallint
Declare @CommenceDateStart smallint
Declare @CommenceDateEnd smallint

Declare @StartDate datetime
DEclare @EndDate datetime
Declare @StartCommDate date
Declare @EndCommDate date

Declare @strStartDate varchar(8)
DEclare @strEndDate varchar(8)
Declare @MinPremium float
Declare @OrderByOption smallint

Select @MinPremium = MinPremium, 
				@QuoteDateStart = QuoteStart, 
				@QuoteDateEnd = QuoteEnd, 
				@CommenceDateStart = CommDateStart, 
				@CommenceDateEnd = CommDateEnd,
				@OrderByOption = OrderByOption
		From tblCXCRMLeadSetting Where [Status] = 1 And SettingID = 1

Select @EndCommDate = GETDATE() + @CommenceDateEnd
Select @StartCommDate = GETDATE() + @CommenceDateStart
Select @StartDate = GETDATE() - @QuoteDateStart
Select @EndDate = GETDATE() -- @QuoteDateEnd

Select @strStartDate = CONVERT(varchar(8), @StartDate, 112)
Select @strEndDate = CONVERT(varchar(8), @EndDate, 112)

Select c.RefCEUserId, up.NInfo7, cp.CoverageCommenceDate, cp.SumInsured, c.CreatedDate from tblCarDetailTH c 
	INNER JOIN tblCarPolicy cp ON c.CarID = cp.CECarID And c.RefCEUserID = cp.RefCEUserID
	INNER JOIN tblCEUsrProfile up ON c.RefCEUserID = up.RefCEUserID
	INNER JOIN tblCEUser u ON u.CEID = up.RefCEUserID
	Where (c.RefCEUserId IS NOT NULL AND c.RefCEUserId > 0) 
	AND c.RefCEUserId NOT IN (Select l.CustomerID from tblCXCRMAgentLeads l Where (Convert(varchar(8), l.CreatedDate, 112) Between Convert(varchar(8), GETDATE() - 60, 112) And Convert(varchar(8), GETDATE(), 112)))
	AND (CONVERT(varchar(8), c.CreatedDate, 112) Between @strStartDate And @strEndDate) And c.RefCEUserId > 0
	-- *****START 30 Minutes IS HERE*****
	AND DATEDIFF(minute, c.CreatedDate, GetDate()) >= 15 
	-- *****END 30 Minutes IS HERE*****
	AND (cp.CoverageCommenceDate Between @StartCommDate And @EndCommDate)
	AND ((c.Info7 NOT Like '%[A-Z,a-z]%' AND c.Info8 NOT Like '%[A-Z,a-z]%') OR (up.NInfo7 = 1 OR up.NInfo7 = 0))
	And u.UsrTypeId = 400 AND (u.UserID = 'CEUSERAUTOIDCI' OR u.UserID = 'CEUSERAUTOIDMOBILECI')
	ORDER BY cp.CreatedDate DESC, cp.CoverageCommenceDate ASC
	--Order By cp.SumInsured DESC, cp.CoverageCommenceDate ASC

	Declare @Broker1PendingCount int
	Declare @Broker8PendingCount int

	DECLARE @@tblAgentPendingLead TABLE 
	(
		AgentID bigint,
		[Status] smallint,
		[AgentType] varchar(3),
		[PendingCount] int
	)
	
	DECLARE @@tblTempAgentPendingLead TABLE 
	(
		AgentID bigint,
		[Status] smallint,
		[AgentType] varchar(3),
		[PendingCount] int
	)
	
	--Get Temp Counting (May not include all agentID)
	INSERT INTO @@tblTempAgentPendingLead (AgentID, [Status], [AgentType], [PendingCount])
	select l.AgentID, l.[Status], u.Info1 AS AgentType, Count(l.AgentLeadID) AS [PendingCount] 
	FROM tblCXCRMAgentLeads l 
	INNER JOIN tblCEUser u ON l.AgentID = u.CEID
	Where u.[Status] = 1 AND u.UsrTypeID = 200 AND (u.Info1 = 'ONS' OR u.Info1 = 'ONJ')
	AND (l.[Status] = 1)
	--And l.IsFromService = 2 And Convert(varchar(8), l.CreatedDate, 112) > '20121101'
	And (l.CallType = 100 OR l.CallType = 101) 
	--And l.AgentID IN (45053, 4425, 547, 18808, 8543, 18813, 18818, 6807)
	And l.CustomerID > 0
	Group By l.AgentID, l.[Status], u.Info1
	
	--Create All Agent PendindCount = 0
	INSERT INTO @@tblAgentPendingLead (AgentID, [Status], [AgentType], [PendingCount])
	select CEID, 1, Info1,  0 From tblCEUser 
	--WHERE CEID IN (45053, 4425, 547, 18808, 8543, 18813, 18818, 6807)
	WHERE [Status] = 1 AND UsrTypeID = 200 AND (Info1 = 'ONS' OR Info1 = 'ONJ')
	
	--Get Pending Count from Temp
	Update l SET l.PendingCount = t.PendingCount
	From @@tblTempAgentPendingLead t INNER JOIN  @@tblAgentPendingLead l ON t.AgentID = l.AgentID

	
	--****Call Back Due in Next 2 Hours to PendingCound****
	DELETE from @@tblTempAgentPendingLead
	
	select 'Call Back Due in Next 2 Hours', s.CallBackAgentID, l.[Status], Count(l.AgentLeadID) AS [PendingCount] 
	FROM tblCXCRMAgentLeads l 
	INNER JOIN tblCEUser u ON l.AgentID = u.CEID
	LEFT JOIN tblCXCRMCallStatus s ON l.AgentLeadID = s.AgentLeadID And l.AgentID = s.AgentID And l.CallType = s.CallTypeID
	Where u.[Status] = 1 AND u.UsrTypeID = 200 AND (u.Info1 = 'ONS' OR u.Info1 = 'ONJ')
	AND (l.[Status] = 2) And Convert(varchar(8), l.CreatedDate, 112) > '20121101'
	And (l.CallType = 100 OR l.CallType = 101) 
	--And l.AgentID IN (45053, 4425, 547, 18808, 8543, 18813, 18818, 6807)
	And l.CustomerID > 0 And s.CallBackDateTime <= DateAdd(hour, 2, GetDate())
	Group By s.CallBackAgentID, l.[Status]
	
	INSERT INTO @@tblTempAgentPendingLead (AgentID, [Status], [PendingCount])
	select s.CallBackAgentID, l.[Status], Count(l.AgentLeadID) AS [PendingCount] 
	FROM tblCXCRMAgentLeads l 
	INNER JOIN tblCEUser u ON l.AgentID = u.CEID
	LEFT JOIN tblCXCRMCallStatus s ON l.AgentLeadID = s.AgentLeadID And l.AgentID = s.AgentID And l.CallType = s.CallTypeID
	Where u.[Status] = 1 AND u.UsrTypeID = 200 AND (u.Info1 = 'ONS' OR u.Info1 = 'ONJ')
	AND (l.[Status] = 2) And Convert(varchar(8), l.CreatedDate, 112) > '20121101'
	And (l.CallType = 100 OR l.CallType = 101) 
	--And l.AgentID IN (45053, 4425, 547, 18808, 8543, 18813, 18818, 6807)
	And l.CustomerID > 0 And s.CallBackDateTime <= DateAdd(hour, 2, GetDate())
	Group By s.CallBackAgentID, l.[Status]
	
	Update l SET l.PendingCount = l.PendingCount + t.PendingCount
	From @@tblTempAgentPendingLead t INNER JOIN  @@tblAgentPendingLead l ON t.AgentID = l.AgentID
	--****END Call Back Due in Next 2 Hours to PendingCound****
	
	Select 'NEW', u.Info1, u.Email, u.CEID, l.PendingCount from @@tblAgentPendingLead l INNER JOIN tblCEUser u
	ON l.AgentID = u.CEID
	
	--****Follow Due in Next 2 Hours to PendingCound*****
	DELETE from @@tblTempAgentPendingLead
	
	select 'Follow Due in Next 2 Hours', l.AgentID, l.[Status], Count(l.AgentLeadID) AS [PendingCount] 
	FROM tblCXCRMAgentLeads l
	INNER JOIN tblCEUser u ON l.AgentID = u.CEID
	Where u.[Status] = 1 AND u.UsrTypeID = 200 AND (u.Info1 = 'ONS' OR u.Info1 = 'ONJ')
	AND (l.[Status] = 3) And Convert(varchar(8), l.CreatedDate, 112) > '20121101'
	And (l.CallType = 100 OR l.CallType = 101) 
	--And l.AgentID IN (45053, 4425, 547, 18808, 8543, 18813, 18818, 6807)
	And l.CustomerID > 0 And (l.ModifiedDate+1) <= DateAdd(hour, 2, GetDate())
	Group By l.AgentID, l.[Status]
	
	INSERT INTO @@tblTempAgentPendingLead (AgentID, [Status], [PendingCount])
	select l.AgentID, l.[Status], Count(l.AgentLeadID) AS [PendingCount] 
	FROM tblCXCRMAgentLeads l
	INNER JOIN tblCEUser u ON l.AgentID = u.CEID
	Where u.[Status] = 1 AND u.UsrTypeID = 200 AND (u.Info1 = 'ONS' OR u.Info1 = 'ONJ')
	AND (l.[Status] = 3) And Convert(varchar(8), l.CreatedDate, 112) > '20121101'
	And (l.CallType = 100 OR l.CallType = 101) 
	--And l.AgentID IN (45053, 4425, 547, 18808, 8543, 18813, 18818, 6807)
	And l.CustomerID > 0 And (l.ModifiedDate+1) <= DateAdd(hour, 2, GetDate())
	Group By l.AgentID, l.[Status]
	
	Update l SET l.PendingCount = l.PendingCount + t.PendingCount
	From @@tblTempAgentPendingLead t INNER JOIN  @@tblAgentPendingLead l ON t.AgentID = l.AgentID
	--****END Follow Due in Next 2 Hours to PendingCound*****
	
	--****POLICY NOT EXPIRE SO SOON *****
	DELETE from @@tblTempAgentPendingLead
	
	Select 'POLICY NOT EXPIRE SO SOON', c.CallBackAgentID, l.[Status], Count(l.AgentLeadID) AS [PendingCount]
	from tblCXCRMAgentLeads l 
	INNER JOIN tblCXCRMCallStatus c ON l.AgentLeadID = c.AgentLeadID AND c.CallTypeID = l.CallType
	INNER JOIN tblCEUser u ON u.CEID = l.CustomerID		
	Where u.UsrTypeId = 400 AND l.Status = 100 
	And c.MainCallStatusTypeID = 7 And c.CallStatusTypeID = 10
	AND c.CallBackDateTime IS NOT NULL And c.CallBackAgentID IS NOT NULL
	And (DateDiff(Day, GETDATE(), c.CallBackDateTime) <= 45)
	Group By c.CallBackAgentID, l.[Status]
	
	INSERT INTO @@tblTempAgentPendingLead (AgentID, [Status], [PendingCount])
	Select  c.CallBackAgentID, l.[Status], Count(l.AgentLeadID) AS [PendingCount]
	from tblCXCRMAgentLeads l 
	INNER JOIN tblCXCRMCallStatus c ON l.AgentLeadID = c.AgentLeadID AND c.CallTypeID = l.CallType
	INNER JOIN tblCEUser u ON u.CEID = l.CustomerID		
	Where u.UsrTypeId = 400 AND l.Status = 100 
	And c.MainCallStatusTypeID = 7 And c.CallStatusTypeID = 10
	AND c.CallBackDateTime IS NOT NULL And c.CallBackAgentID IS NOT NULL
	And (DateDiff(Day, GETDATE(), c.CallBackDateTime) <= 45)
	Group By c.CallBackAgentID, l.[Status]
	
	Update l SET l.PendingCount = l.PendingCount + t.PendingCount
	From @@tblTempAgentPendingLead t INNER JOIN  @@tblAgentPendingLead l ON t.AgentID = l.AgentID
	--****END POLICY NOT EXPIRE SO SOON *****
	
	DELETE from @@tblTempAgentPendingLead
	
	--Broker 1 Pending Count
	Select @Broker1PendingCount = PendingCount from @@tblAgentPendingLead 
	WHERE AgentID = 547
	
	--Broker 8 Pending Count
	Select @Broker8PendingCount = PendingCount from @@tblAgentPendingLead 
	WHERE AgentID = 18818
	
	Select u.Info1, u.Email, u.CEID, l.PendingCount from @@tblAgentPendingLead l INNER JOIN tblCEUser u
	ON l.AgentID = u.CEID

	--Select top 1 * FROM @@tblAgentPendingLead Where AgentID IN (18808, 8543, 18813, 31575) Order By PendingCount ASC

	Select @Broker1PendingCount Broker1PendingCount, @Broker8PendingCount Broker8PendingCount
	
	--547	broker1 14
	--18808	broker3 33
	--8543	broker5 43
	--18813	broker6 33
	--31575	broker7 30
	--18818	broker8 19
	
	--select top 10 * from tblCarDetailTH where CarID = 44335
	
	--select * from tblCXCRMAgentLeads Where CarID = 44335
	
	--Balance Leads
--	select * from tblCXCRMAgentLeads Where [Status] = 1 And AgentID = 31575

--	Update tblCXCRMAgentLeads SET AgentID = 8543
--	Where [Status] = 1 And AgentID = 31575 And AgentLeadID
--	IN  
--	(26569,
--26594,
--26601)

--select * from tblCXCRMCallStatus Where CallBackAgentID = 31575

--Update tblCXCRMCallStatus SET CallBackAgentID = AgentID Where CallBackAgentID = 31575

select * from tblCEUser Where CEID = 4425